package com.qhhc.service.impl;

import com.qhhc.entity.CarInspection;
import com.qhhc.mapper.CarInspectionMapper;
import com.qhhc.service.CarInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CarInspectionServiceImpl implements CarInspectionService {

    @Autowired
    private CarInspectionMapper carInspectionMapper;

    @Override
    public List<CarInspection> getAllInspections() {
        return carInspectionMapper.selectAll();
    }

    @Override
    public CarInspection getInspectionById(Long inspectionId) {
        return carInspectionMapper.selectById(inspectionId);
    }

    @Override
    public List<CarInspection> getInspectionsByCarId(Long carId) {
        return carInspectionMapper.selectByCarId(carId);
    }

    @Override
    public List<CarInspection> getInspectionsByInspector(String inspector) {
        return carInspectionMapper.selectByInspector(inspector);
    }

    @Override
    public List<CarInspection> getInspectionsByResult(String result) {
        return carInspectionMapper.selectByResult(result);
    }

    @Override
    @Transactional
    public boolean addInspection(CarInspection inspection) {
        return carInspectionMapper.insert(inspection) > 0;
    }

    @Override
    @Transactional
    public boolean updateInspection(CarInspection inspection) {
        return carInspectionMapper.update(inspection) > 0;
    }

    @Override
    @Transactional
    public boolean deleteInspection(Long inspectionId) {
        return carInspectionMapper.deleteById(inspectionId) > 0;
    }

    @Override
    @Transactional
    public boolean deleteInspectionsByCarId(Long carId) {
        return carInspectionMapper.deleteByCarId(carId) > 0;
    }

    @Override
    public List<CarInspection> getInspectionsByCondition(CarInspection inspection) {
        return carInspectionMapper.selectByCondition(inspection);
    }
} 